package com.qef.com.mmovie.mvp.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.qef.com.mmovie.App;
import com.qef.com.mmovie.R;
import com.qef.com.mmovie.base.BaseRecycerViewAdapter;
import com.qef.com.mmovie.entity.SubscriptionDetailsEntity;
import com.qef.com.mmovie.img.ImageLoader;

import java.util.List;

import static com.qef.com.mmovie.R.id.recycler;

/**
 * Created by guangjiego on 2017/7/7.
 */

public class SubscriptionDetailsAdapter extends BaseRecycerViewAdapter<SubscriptionDetailsEntity.ItemListEntityX, SubscriptionDetailsAdapter.MyHoldr> {
    public SubscriptionDetailsAdapter(Context context, List<SubscriptionDetailsEntity.ItemListEntityX> list) {
        super(context, list);
    }

    @Override
    public MyHoldr getCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyHoldr(View.inflate(App.getInstance(), R.layout.item_subscription_details, null));
    }

    @Override
    public void getBindViewHolder(MyHoldr holder, int position) {
        SubscriptionDetailsEntity.ItemListEntityX.DataEntityX.HeaderEntity header = list.get(position).getData().getHeader();
        holder.tvName.setText(header.getTitle());
        holder.tvDis.setText(header.getDescription());
        ImageLoader.getInstance().displayCricleImage(context, header.getIcon(), holder.ivHead);
        List<SubscriptionDetailsEntity.ItemListEntityX.DataEntityX.ItemListEntity> itemList = list.get(position).getData().getItemList();
        LinearLayoutManager layout = new LinearLayoutManager(context);
        layout.setOrientation(LinearLayoutManager.HORIZONTAL);
        holder.rcInfos.setLayoutManager(layout);
//        holder.rcInfos.addItemDecoration(new DividerItemDecoration(App.getInstance(), DividerItemDecoration.VERTICAL));
        holder.rcInfos.setAdapter(new itemDetailsInfoAdapter(context, itemList));
    }

    class MyHoldr extends RecyclerView.ViewHolder {
        ImageView ivHead;
        TextView tvName;
        TextView tvDis;
        RecyclerView rcInfos;

        public MyHoldr(View itemView) {
            super(itemView);
            ivHead = (ImageView) itemView.findViewById(R.id.iv_head);
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
            tvDis = (TextView) itemView.findViewById(R.id.tv_dis);
            rcInfos = (RecyclerView) itemView.findViewById(R.id.rc_infos);
        }
    }
}
